home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / C⁄C++ OS8 / Everything / Checkboxes.cp < prev    next >
Encoding:
Text File  |  1998-09-06  |  10.6 KB  |  469 lines  |  [TEXT/CWIE]

  1. // Checkboxes.cp
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15.  
  16. #include "Globals.h"
  17. #include "ResourceDefs.h"
  18. #include "DoScrap.h"
  19. #include "Miscellany.h"
  20. #include "Scrolling.h"
  21. #include "ControlUtils.h"
  22. #include "DDocData.h"
  23. #include "EverythingEngine.h"
  24. #include "EverythingDoc.h"
  25.  
  26. #include "Checkboxes.h"
  27.  
  28.  
  29. //----------
  30. void    Checkboxes::Create (
  31.     AMDoc*            inDoc,
  32.     DDocData*        inData)
  33. {
  34.     Checkboxes*        winObj = new Checkboxes;
  35.  
  36.     if (winObj != nil) {
  37.         winObj->Open (inDoc);
  38.         winObj->ConnectToData (inData);
  39.     }
  40. }
  41.  
  42. //----------
  43. Checkboxes::Checkboxes ()
  44. {
  45.     mData = nil;
  46. }
  47.  
  48. //----------
  49. Checkboxes::~Checkboxes ()
  50. {
  51. }
  52.  
  53. //----------
  54. EverythingEngine*    Checkboxes::GetEngine ()
  55. {
  56.     return (EverythingEngine*) mDoc->mEngine;
  57. }
  58.  
  59. //----------
  60. void    Checkboxes::Open (
  61.     AMDoc*            inDoc)
  62. {
  63.     WindowPtr        window;
  64.     Handle            wftb;
  65.  
  66.     mDoc = inDoc;
  67.  
  68.     window = GetNewCWindow (WIND_Checkboxes, nil, (WindowPtr) -1L);
  69.     if (mDoc->mEngine->GetFilename () [0] != 0) {
  70.         SetWTitle (window, mDoc->mEngine->GetFilename ());
  71.     }
  72.     mWindow = window;
  73.     ((EverythingDoc*)mDoc)->mCheckboxesPtr = window;
  74.  
  75.     SetWindowKind (window, 'AM');
  76.     SetWRefCon (window, (long) this);
  77.     SetPort (window);
  78.     SetInfo (window);
  79.  
  80.     wftb = ::GetResource ('Wftb', WIND_Checkboxes);
  81.  
  82.     CreateRootControl (window, &mRootControl);
  83.  
  84.     vScroll = nil;
  85.     hScroll = nil;
  86.  
  87.  
  88.     mStandard2Handle = ::GetNewControl (CNTL_Standard2, window);
  89.     SetWindowItemFont (mStandard2Handle, wftb, 1);
  90.  
  91.     mXxHandle = ::GetNewControl (CNTL_Xx, window);
  92.     SetWindowItemFont (mXxHandle, wftb, 2);
  93.  
  94.     mCapTriangleLabel = GetNewControl (CNTL_CapTriangle, window);
  95.     SetWindowItemFont (mCapTriangleLabel, wftb, 3);
  96.     SetControlFromTEXT (mCapTriangleLabel, TEXT_CapTriangle);
  97.  
  98.  
  99.     mGraphic2Handle = ::GetNewControl (CNTL_Graphic2, window);
  100.     SetWindowItemFont (mGraphic2Handle, wftb, 4);
  101.  
  102.     mCapcicn2Label = GetNewControl (CNTL_Capcicn2, window);
  103.     EmbedControl (mCapcicn2Label, mGraphic2Handle);
  104.     SetWindowItemFont (mCapcicn2Label, wftb, 5);
  105.     SetControlFromTEXT (mCapcicn2Label, TEXT_Capcicn2);
  106.  
  107.     mLRHandle = ::GetNewControl (CNTL_LR, window);
  108.     EmbedControl (mLRHandle, mGraphic2Handle);
  109.     SetWindowItemFont (mLRHandle, wftb, 6);
  110.  
  111.     mCapicl10Label = GetNewControl (CNTL_Capicl10, window);
  112.     EmbedControl (mCapicl10Label, mGraphic2Handle);
  113.     SetWindowItemFont (mCapicl10Label, wftb, 7);
  114.     SetControlFromTEXT (mCapicl10Label, TEXT_Capicl10);
  115.  
  116.     mLR2Handle = ::GetNewControl (CNTL_LR2, window);
  117.     EmbedControl (mLR2Handle, mGraphic2Handle);
  118.     SetWindowItemFont (mLR2Handle, wftb, 8);
  119.  
  120.     mCapICN2Label = GetNewControl (CNTL_CapICN2, window);
  121.     EmbedControl (mCapICN2Label, mGraphic2Handle);
  122.     SetWindowItemFont (mCapICN2Label, wftb, 9);
  123.     SetControlFromTEXT (mCapICN2Label, TEXT_CapICN2);
  124.  
  125.     mLR3Handle = ::GetNewControl (CNTL_LR3, window);
  126.     EmbedControl (mLR3Handle, mGraphic2Handle);
  127.     SetWindowItemFont (mLR3Handle, wftb, 10);
  128.  
  129.     mCapPICT2Label = GetNewControl (CNTL_CapPICT2, window);
  130.     EmbedControl (mCapPICT2Label, mGraphic2Handle);
  131.     SetWindowItemFont (mCapPICT2Label, wftb, 11);
  132.     SetControlFromTEXT (mCapPICT2Label, TEXT_CapPICT2);
  133.  
  134.     mLR4Handle = ::GetNewControl (CNTL_LR4, window);
  135.     EmbedControl (mLR4Handle, mGraphic2Handle);
  136.     SetWindowItemFont (mLR4Handle, wftb, 12);
  137.  
  138.     mCheckboxHandle = ::GetNewControl (CNTL_Checkbox, window);
  139.     EmbedControl (mCheckboxHandle, mGraphic2Handle);
  140.     SetWindowItemFont (mCheckboxHandle, wftb, 13);
  141.  
  142.     mCapicl11Label = GetNewControl (CNTL_Capicl11, window);
  143.     EmbedControl (mCapicl11Label, mGraphic2Handle);
  144.     SetWindowItemFont (mCapicl11Label, wftb, 14);
  145.     SetControlFromTEXT (mCapicl11Label, TEXT_Capicl11);
  146.  
  147.  
  148.     mBevel2Handle = ::GetNewControl (CNTL_Bevel2, window);
  149.     SetWindowItemFont (mBevel2Handle, wftb, 15);
  150.  
  151.     mCheckbox2Handle = ::GetNewControl (CNTL_Checkbox2, window);
  152.     EmbedControl (mCheckbox2Handle, mBevel2Handle);
  153.     SetWindowItemFont (mCheckbox2Handle, wftb, 16);
  154.     SetBevelButtonGraphicAlignment (mCheckbox2Handle, kControlBevelButtonAlignCenter, 0, 0);
  155.  
  156.     mNext3Handle = ::GetNewControl (CNTL_Next3, window);
  157.     EmbedControl (mNext3Handle, mBevel2Handle);
  158.     SetWindowItemFont (mNext3Handle, wftb, 17);
  159.     SetBevelButtonTextPlacement (mNext3Handle, kControlBevelButtonPlaceToRightOfGraphic);
  160.     SetBevelButtonTextAlignment (mNext3Handle, kControlBevelButtonAlignTextFlushLeft, 0);
  161.     SetBevelButtonGraphicAlignment (mNext3Handle, kControlBevelButtonAlignLeft, 0, 0);
  162.  
  163.     mNext4Handle = ::GetNewControl (CNTL_Next4, window);
  164.     EmbedControl (mNext4Handle, mBevel2Handle);
  165.     SetWindowItemFont (mNext4Handle, wftb, 18);
  166.     SetBevelButtonTextPlacement (mNext4Handle, kControlBevelButtonPlaceBelowGraphic);
  167.     SetBevelButtonTextAlignment (mNext4Handle, kControlBevelButtonAlignTextCenter, 0);
  168.     SetBevelButtonGraphicAlignment (mNext4Handle, kControlBevelButtonAlignTop, 0, 0);
  169.  
  170.     AdvanceKeyboardFocus (window);
  171.  
  172.     ShowWindow (window);
  173. }
  174.  
  175. //----------
  176. void    Checkboxes::Close ()
  177. {
  178.     mData->RemoveResponder (this);
  179.  
  180.     ((EverythingDoc*)mDoc)->mCheckboxesPtr = nil;
  181.     SetInfo (nil);
  182.     HideWindow (mWindow);
  183.     DisposeWindow (mWindow);
  184.  
  185.     delete this;
  186. }
  187.  
  188. //----------
  189. void    Checkboxes::ConnectToData (
  190.     DDocData*        inData)
  191. {
  192.     mData = inData;
  193.     mData->AddResponder (this);
  194.  
  195.     SetControlValue (mStandard2Handle, mData->GetStandard ());
  196.     SetControlValue (mXxHandle, mData->GetXx ());
  197.     SetControlValue (mLRHandle, mData->GetLR ());
  198.     SetControlValue (mLR2Handle, mData->GetLR2 ());
  199.     SetControlValue (mLR3Handle, mData->GetLR3 ());
  200.     SetControlValue (mLR4Handle, mData->GetLR4 ());
  201.     SetControlValue (mCheckboxHandle, mData->GetCheckbox ());
  202.     SetControlValue (mCheckbox2Handle, mData->GetCheckbox2 ());
  203.     SetControlValue (mNext3Handle, mData->GetNext ());
  204.     SetControlValue (mNext4Handle, mData->GetNext2 ());
  205. }
  206.  
  207. //----------
  208. void    Checkboxes::DataChanged (
  209.     long        inDataID)
  210. {
  211.     if (inDataID == idStandard) {
  212.         SetControlValue (mStandard2Handle, mData->GetStandard ());
  213.     }
  214.     if (inDataID == idXx) {
  215.         SetControlValue (mXxHandle, mData->GetXx ());
  216.     }
  217.     if (inDataID == idLR) {
  218.         SetControlValue (mLRHandle, mData->GetLR ());
  219.     }
  220.     if (inDataID == idLR2) {
  221.         SetControlValue (mLR2Handle, mData->GetLR2 ());
  222.     }
  223.     if (inDataID == idLR3) {
  224.         SetControlValue (mLR3Handle, mData->GetLR3 ());
  225.     }
  226.     if (inDataID == idLR4) {
  227.         SetControlValue (mLR4Handle, mData->GetLR4 ());
  228.     }
  229.     if (inDataID == idCheckbox) {
  230.         SetControlValue (mCheckboxHandle, mData->GetCheckbox ());
  231.     }
  232.     if (inDataID == idCheckbox2) {
  233.         SetControlValue (mCheckbox2Handle, mData->GetCheckbox2 ());
  234.     }
  235.     if (inDataID == idNext) {
  236.         SetControlValue (mNext3Handle, mData->GetNext ());
  237.     }
  238.     if (inDataID == idNext2) {
  239.         SetControlValue (mNext4Handle, mData->GetNext2 ());
  240.     }
  241. }
  242.  
  243. //----------
  244. void    Checkboxes::Control (
  245.     ControlHandle        whichControl,
  246.     short                whichPart,
  247.     Point                where)
  248. {
  249.     Rect            bounds;
  250.     short            newValue;
  251.  
  252.     ExitCurField ();
  253.  
  254.     if (whichControl == mStandard2Handle) {
  255.         if (TrackCheckbox (mStandard2Handle, where)) {
  256.             mData->SetStandard (GetControlValue (mStandard2Handle) != 0);
  257.         }
  258.     }
  259.     if (whichControl == mXxHandle) {
  260.         if (TrackCheckbox (mXxHandle, where)) {
  261.             mData->SetXx (GetControlValue (mXxHandle) != 0);
  262.         }
  263.     }
  264.     if (whichControl == mLRHandle) {
  265.         if (TrackCheckbox (mLRHandle, where)) {
  266.             mData->SetLR (GetControlValue (mLRHandle) != 0);
  267.         }
  268.     }
  269.     if (whichControl == mLR2Handle) {
  270.         if (TrackCheckbox (mLR2Handle, where)) {
  271.             mData->SetLR2 (GetControlValue (mLR2Handle) != 0);
  272.         }
  273.     }
  274.     if (whichControl == mLR3Handle) {
  275.         if (TrackCheckbox (mLR3Handle, where)) {
  276.             mData->SetLR3 (GetControlValue (mLR3Handle) != 0);
  277.         }
  278.     }
  279.     if (whichControl == mLR4Handle) {
  280.         if (TrackCheckbox (mLR4Handle, where)) {
  281.             mData->SetLR4 (GetControlValue (mLR4Handle) != 0);
  282.         }
  283.     }
  284.     if (whichControl == mCheckboxHandle) {
  285.         if (TrackCheckbox (mCheckboxHandle, where)) {
  286.             mData->SetCheckbox (GetControlValue (mCheckboxHandle) != 0);
  287.         }
  288.     }
  289.     if (whichControl == mCheckbox2Handle) {
  290.         if (TrackClick (mCheckbox2Handle, where)) {
  291.             mData->SetCheckbox2 (GetControlValue (mCheckbox2Handle) != 0);
  292.         }
  293.     }
  294.     if (whichControl == mNext3Handle) {
  295.         if (TrackClick (mNext3Handle, where)) {
  296.             mData->SetNext (GetControlValue (mNext3Handle) != 0);
  297.         }
  298.     }
  299.     if (whichControl == mNext4Handle) {
  300.         if (TrackClick (mNext4Handle, where)) {
  301.             mData->SetNext2 (GetControlValue (mNext4Handle) != 0);
  302.         }
  303.     }
  304. }
  305.  
  306. //----------
  307. void    Checkboxes::MouseIn (
  308.     Point        where,
  309.     short        modifiers)
  310. {
  311.     Rect        bounds;
  312.  
  313. }
  314.  
  315. //----------
  316. void    Checkboxes::ExitCurField ()
  317. {
  318.     ControlHandle    focus;
  319.  
  320.     GetKeyboardFocus (mWindow, &focus);
  321.  
  322.     if (focus == nil) {
  323.         // nothing to exit
  324.  
  325.     }
  326. }
  327.  
  328. //----------
  329. void    Checkboxes::TypeIn (
  330.     char        ch)
  331. {
  332.     ControlHandle    focus;
  333.     SInt16            keyCode;
  334.  
  335.     GetKeyboardFocus (mWindow, &focus);
  336.  
  337.     if ((ch == charEnter)
  338.     ||  (ch == charReturn)) {
  339.         ExitCurField ();
  340.     } else if (ch == charEsc) {
  341.     } else if (ch == charTab) {
  342.         DoTab ((curEvent.modifiers & optionKey) != 0);
  343.     } else if (focus != nil) {
  344.         keyCode = (SInt16)(curEvent.message & keyCodeMask);
  345.         HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
  346.         mDoc->mEngine->SetDirty ();
  347.     } else {
  348.         SysBeep (1);
  349.     }
  350. }
  351.  
  352. //----------
  353. void    Checkboxes::Resize ()
  354. {
  355.     /* application-specific code to resize items in window */
  356. }
  357.  
  358. //----------
  359. void    Checkboxes::Scroll (
  360.     short        newValue,
  361.     short        oldValue)
  362. {
  363.     /* application-specific code to scroll window */
  364.     if (gWhichScroll == vScroll) {
  365.     } else {    // horizontal
  366.     }
  367. }
  368.  
  369. //----------
  370. void    Checkboxes::DoUndo ()
  371. {
  372. } // DoUndo
  373.  
  374. //----------
  375. void    Checkboxes::DoCut ()
  376. {
  377.     TEHandle        curTE = GetCurTE ();
  378.  
  379.     if (curTE != nil) {
  380.         TECut (curTE);
  381.         mDoc->mEngine->SetDirty ();
  382.         scrapDirty = true;
  383.     }
  384. } // DoCut
  385.  
  386. //----------
  387. void    Checkboxes::DoCopy ()
  388. {
  389.     TEHandle        curTE = GetCurTE ();
  390.  
  391.     if (curTE != nil) {
  392.         TECopy (curTE);
  393.         scrapDirty = true;
  394.     }
  395. } // DoCopy
  396.  
  397. //----------
  398. void    Checkboxes::DoPaste ()
  399. {
  400.     TEHandle        curTE = GetCurTE ();
  401.  
  402.     if (curTE != nil) {
  403.         TEPaste (curTE);
  404.         mDoc->mEngine->SetDirty ();
  405.     }
  406. } // DoPaste
  407.  
  408. //----------
  409. void    Checkboxes::DoClear ()
  410. {
  411.     TEHandle        curTE = GetCurTE ();
  412.  
  413.     if (curTE != nil) {
  414.         TEDelete (curTE);
  415.         mDoc->mEngine->SetDirty ();
  416.     }
  417. } // DoClear
  418.  
  419. //----------
  420. void    Checkboxes::DoSelectAll ()
  421. {
  422.     TEHandle        curTE = GetCurTE ();
  423.  
  424.     if (curTE != nil) {
  425.         TESetSelect (0, 32767, curTE);
  426.     }
  427. } // DoSelectAll
  428.  
  429. //----------
  430. void    Checkboxes::DoShowClipboard ()
  431. {
  432. } // DoShowClipboard
  433.  
  434. //----------
  435. Boolean        Checkboxes::DoCommand (
  436.     long        inCommand)
  437. {
  438.     Boolean        result = true;
  439.  
  440.     switch (inCommand) {
  441.         case cmdUndo:
  442.                 DoUndo ();
  443.             break;
  444.         case cmdCut:
  445.                 DoCut ();
  446.             break;
  447.         case cmdCopy:
  448.                 DoCopy ();
  449.             break;
  450.         case cmdPaste:
  451.                 DoPaste ();
  452.             break;
  453.         case cmdClear:
  454.                 DoClear ();
  455.             break;
  456.         case cmdSelectAll:
  457.                 DoSelectAll ();
  458.             break;
  459.         case cmdShowClipboard:
  460.                 DoShowClipboard ();
  461.             break;
  462.  
  463.         default:
  464.                 result = false;
  465.     } // switch
  466.  
  467.     return result;
  468. }
  469.